/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 98152
 * Date: 2024-10-31
 * Time: 14:45
 */
public class Test1 {
    public static int getLongestPalindrome (String A) {
        // write code here
        int len = A.length();
        int max = 0;
        for (int i = 0; i < len; i++) {
            int index = i;
            int count = 0;
            for (int j = len - 1; index < len && j >= index; j--) {
                if (A.charAt(index) == A.charAt(j)) {
                    if (index == j) {
                        count++;
                    } else {
                        count += 2;
                    }
                    index++;
                } else {
                    count = 0;
                    index = i;
                    if (A.charAt(index) == A.charAt(j)) {
                        if (index == j) {
                            count++;
                        } else {
                            count += 2;
                        }
                        index++;
                    }
                }
            }
            if (count > max) {
                max = count;
            }
        }
        return max;
    }

    public static void main(String[] args) {
        String str = "cababbaca";
        System.out.println(getLongestPalindrome(str));
    }
}
